#!/usr/bin/python
# coding = "utf-8"
import json
import time
import Assembly_Clock
import Assembly_Email
import ColorControl

# 二层防御警戒
# main
ColorControl.printBlue(
    '!!!' + time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + '!!!' + "Layer 2 Defense System Activated")
ColorControl.printWhite("")
fans = open("data.json", "r", encoding="utf-8-sig")
text_data = fans.read()
if text_data.startswith(u'\ufeff'):
    text_data = text_data.encode('utf8')[3:].decode('utf8')
fanText = json.loads(text_data)
user = fanText["user"]
wrongFlag1 = 0
for i in user:
    result2 = Assembly_Clock.clockIn(i['name'], i['number'], i['content'])
    if result2 == 500:
        wrongFlag1 = 1
    time.sleep(1)
fans.close()
# 发送邮件
if wrongFlag1 == 1:
    Assembly_Email.send_email('2479711422@qq.com', 500, 0)
else:
    Assembly_Email.send_email('2479711422@qq.com', 200, 0)
